package com.google.android.c2dm;

import com.utils.HttpUtils;
import com.utils.Utils;

import android.content.Context;
import android.preference.PreferenceManager;
import android.util.Log;

public class GCMUtils {
	public static final boolean setRegId(Context context,
			String value) {
		try {
			submitPushKey(context,value);
			return PreferenceManager.getDefaultSharedPreferences(context).edit()
					.putString(GCMConstants.KEY_REGISTRATION_ID, value).commit();
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
	}
	public static final String getRegId(Context context) {
		return PreferenceManager.getDefaultSharedPreferences(context)
				.getString(GCMConstants.KEY_REGISTRATION_ID, null);
	}
	
	private static void submitPushKey(Context context,String value){
		try {		
			Log.i("DREG", "KEY="+value);
			HttpUtils.submitPushKey(Utils.getDeviceId(context), value);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
